<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>桥梁系统——表单demo</title>
<block th:replace="commonBase"></block>   
</head>
<body>
<div style="width:100%;">
			<div class="mini-toolbar" style="border-bottom:0;padding:0px;">
					<table style="width:100%;">
						<tr>
			                 <td style="width:100%;" > 
			                 <!--  	<a  sec:authorize="hasAuthority('person:add')"     class="mini-button"  plain="true"  iconCls="icon-addnew" onclick="add">添加</a>
			                 	<a  sec:authorize="hasAuthority('person:update')"  class="mini-button"  plain="true"  iconCls="icon-edit"   onclick="edit">修改</a>
			                 	<a  sec:authorize="hasAuthority('person:delete')"  class="mini-button"  plain="true"  iconCls="icon-remove" onclick="remove">删除</a>  -->
			                 	
			                 	<a    class="mini-button"  plain="true"  iconCls="icon-addnew" onclick="add">添加</a>
			                 	<a    class="mini-button"  plain="true"  iconCls="icon-edit"   onclick="edit">修改</a>
			                 	<a    class="mini-button"  plain="true"  iconCls="icon-remove" onclick="remove">删除</a> 
			                  </td>	
							 <td style="white-space:nowrap;">
									<input id="searchKey" class="mini-textbox" emptyText="请输入名称或年龄" style="width:150px;" onenter="search"/>
									<a class="mini-button"   iconCls="icon-search" onclick="search()">查询</a>
								 </td> 
						</tr>
					</table>
				</div>
		</div>
		<div class="mini-fit">
				<div id="grid1" class="mini-datagrid"
					style="width:100%;height:100%;" 
					allowCellSelect="true" multiSelect="true" allowAlternating="false" sortField="birthday" sortOrder="desc" idField="id" pageSize="15" sizeList="[10,15,20,50,100]"
					 th:attr="url=@{/example/person/pagelist}"  >
					<div property="columns">
						<div type="checkcolumn"></div>
						<div field="name"  sortField="name" width="100" allowSort="true">名称</div>
						<div field="age" sortField="age" width="100" allowSort="true" >年龄</div>
						<div field="birthday" sortField="birthday" width="100" allowSort="true" renderer="ondayRenderer">操作日期</div>
						<div field="remark" sortField="remark" width="100" allowSort="true" >备注</div>
					</div>
				</div>
		</div>
</body>

<script th:inline="javascript" type="text/javascript">
 /*<![CDATA[*/


var grid =  null;//表格对象
$(function(){
	  mini.parse();
	  grid = mini.get("grid1");
	  search();
});
/***查询***/
function search() {
	var  searchKey= mini.get("searchKey").getValue();
	if(searchKey!=""){
		grid.load({"searchPhrase":searchKey});
	}else{
		grid.load();
	}
}
function add(){
	 mini.open({
        url:basePath+"example/person/edit",
        title: "新增xx", iconCls:'icon-addnew', width: 600, height: 350,
        onload: function () {
            var iframe = this.getIFrameEl();
            var data = { action:"new"};
            iframe.contentWindow.setData(data);
        },
        ondestroy: function (action) {
			if (action != "close" && action != "cancle"){
        		  search();
			}
        }
    });

}
function edit(){
	var rows = grid.getSelecteds();
	if(rows.length>1){
		mini.alert("只能选择一条记录!");
		return;
	}
	var row = grid.getSelected();
    if (row) {
			 mini.open({
		        url:basePath+"example/person/edit",
		        title: "修改xx", iconCls:'icon-edit', width: 528, height: 360,
		        onload: function () {
		             var iframe = this.getIFrameEl();
		            var data = {action:"edit",person:row};
		            iframe.contentWindow.setData(data);
		        },
		        ondestroy: function (action) {
					if (action != "close" && action != "cancle"){
		        		  search();
					}
		        }
		    });
    }

}
// 删除
function remove(){
	var rows = grid.getSelecteds();
	if (rows.length > 0 ){
		//mini.confirm("确定删除选中记录？","提示!",function(e){
			//if (e == "ok"){
				var rowArray = [];// 当前删除行的数组
				var rowIndex = 0;
			    if (rows.length > 0) {
			        // 当前选中列数据循环检测
			  		$.each(rows,function (idx,rowsObj){
			  			var nid = rowsObj.id;
						rowArray[rowIndex++] = nid;
			  		});
			       if (rowArray.length != 0){
			       		var ids = rowArray.toString();
			       		 $.ajax({
			       			url:basePath+"example/person/delete?ids="+ids,
			       			type:"delete",
			       			data:null,
			       			success:function(successData){
			       	        	var message = mini.decode(successData);
					        	if(message.type == '200'){
					            	showMsg("xx删除成功","success",800,"center","center");
					        	    search();
					        	}else{
					        		showMsg("xx删除失败","warning",800,"center","center");
					        	}
			       			},
			       			error:function(errorData){
	        	 				showMsg("xx删除错误","danger",800,"center","center");
			       			}
			       		}); 
			       }
			    }
		//	}
		//});
	}else{
		mini.alert("请选中一条记录!");
	}
}



function ondayRenderer(e){
		var birthday = e.value;
       	if(!birthday){
       		return "";
       	}
        return format(birthday, 'yyyy-MM-dd HH:mm:ss');
}


/*]]>*/
</script>
</html>